package com.qingyun.student.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qingyun.common.dto.Result;
import com.qingyun.student.entity.Student;
import com.qingyun.student.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生表 前端控制器
 * </p>
 *
 * @author your_name
 * @since 2025-08-23
 */
@RestController
public class StudentController {
    @Autowired
    private IStudentService studentService;
    @GetMapping("/studentInfo")
    public Result studentInfo(
            @RequestHeader("Authorization") String token,
            @RequestParam(value = "keyword", required = false,defaultValue = "") String keyword
    ) {
        if(token.isEmpty()){
            return Result.fail("获取用户失败，请联系管理员");
        }
        return studentService.studentInfo(token,keyword);
    }

    @GetMapping("/internal/byName")
    public Student getStudentByName(@RequestParam String studentName){
        Student student1 = studentService.getOne(new LambdaQueryWrapper<Student>()
                .eq(Student::getName, studentName).last("limit 1"));
        return student1;
    }


    @GetMapping("/internal/byId")
    public Student queryStudentById(@RequestParam Long studentId){
        return studentService.getBaseMapper()
                .selectOne(new LambdaQueryWrapper<Student>()
                        .eq(Student::getId, studentId));
    }



}
